
import os

def get_file_path(directory_path):
    # 设定要读取的文件夹路径
    # directory_path = '/Users/chongwen/Desktop/工作项目/AI/济南AI项目/部署/案例数据/zip_bak/20210928/'

    infos_all = []
    # 读取文件夹内的内容
    for province in os.listdir(directory_path):# 省份
        # 构建完整的文件夹路径
        folder_path = os.path.join(directory_path, province)

        # 检查是否为文件夹
        if os.path.isdir(folder_path):
            # 读取文件夹内的内容
            for court_name in os.listdir(folder_path): # 省份
                file_path = os.path.join(folder_path, court_name)
                if os.path.isfile(file_path):
                    pass
                elif os.path.isdir(file_path):
                    for case_type in os.listdir(file_path): # 省份下地市
                        file_path1 = os.path.join(file_path, case_type)
                        if os.path.isdir(file_path1):
                            for filename in os.listdir(file_path1): # 案件类型
                                file_path2 = os.path.join(file_path1, filename)
                                # print(file_path) # 文书
                                # print('\n')
                                # 省份、省份下地市法院、案件类型、文书路径
                                infos_all.append([province, court_name, case_type, filename, file_path2])

    return infos_all





def get_writ(xml_file_path=''):
    import xml.etree.ElementTree as ET

    # 文件的路径
    xml_file_path = '/Users/chongwen/Code/myCode/djangoProject/utils/es_upload_utils/new_case/类别.xml'
    # 使用ElementTree解析XML文件
    tree = ET.parse(xml_file_path)
    filenames = []

    # 获取根元素
    root = tree.getroot()
    # key-value
    type_map, parent_map = {}, {}

    # 遍历所有<Item>元素
    for item in root.findall('Item'):
        # 提取<key>、<parentkey>和<value>
        key = item.find('key').text
        parentkey = item.find('parentkey').text
        value = item.find('value').text

        if value[-1] == '罪' or value[-2:] == '纠纷':
            filenames.append(value)

        type_map[key] = value
        parent_map[key] = parentkey

    print(len(type_map))
    return type_map, parent_map, filenames


# if __name__ == "__main__":
#     get_file_path()

